package src.java.easy;

import java.util.HashMap;

public class Solution169 {
    public int majorityElement(int[] nums) {
        int n = nums.length / 2;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            Integer sum = map.getOrDefault(num, 0);
            if (sum > n) return num;
            map.put(num, sum + 1);
        }
        for (Integer integer : map.keySet()) {
            if (map.get(integer) > n) return integer;
        }
        return -1;
    }
}
